/***************************************************************************
 *   Copyright (C) 2005 by xihe   *
 *   xihels@163.com                                                        *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/
#include "ImPacketFont.h"
const char default_font_name[] = {
    0xcb, 0xce, 0xcc, 0xe5, 0x00
};

ImPacketFont::ImPacketFont() :
    red(0x00),
    green(0x00),
    blue(0x00),
    fontName(default_font_name)
{
    // bzero(&font, sizeof (font));
    bzero(&font, sizeof(font));
    font.size = 9;
}

int ImPacketFont::putBody(uint8_t* buf) const {
    uint8_t* cur = buf;
    cur += writeBufW(cur, 0x2000);  // 空格和0x0
    cur += writeBufB(cur, *(uint8_t*)(void*)(&font));
    cur += writeBufB(cur, red);
    cur += writeBufB(cur, green);
    cur += writeBufB(cur, blue);
    cur += writeBufB(cur, 0x00);    // 1个未知字节
    // 消息编码，2字节，0x8602为GB，0x0000为EN，其他未知
    cur += writeBufW(cur, QQ_IM_ENCODING_GB);
    // 可变长度的一段信息，字体名后面跟一个回车符，比如0xcb, 0xce, 0xcc, 0xe5表示宋体
    cur += writeBufData(cur, (const uint8_t*)fontName.c_str(), fontName.length());
    *cur++ = 0x0d;
    // 1字节，表示本段字节长度
    //uint8_t len = cur - buf;
    //cur += writeBufB(cur, len);
    return cur - buf;
}

